﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TireService.Data;

namespace TireService.Web.View
{
    public partial class OpdaterAbonnement : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void ASPxButton1_Click(object sender, EventArgs e)
        {
            TireServiceDB db = new TireServiceDB();

            List<CustomerSubscription> subscriptions = db.CustomerSubscriptions.Where(p => p.InActive == false & p.SubscriptionId != 4 & p.SubscriptionId != 15 & p.CustomerId != 10004 & p.CustomerId != 10005 & p.CustomerId != 10007 & p.CustomerId != 10008 & p.CustomerId != 10009 & p.CustomerId != 10010 & p.CustomerId != 10011 & p.CustomerId != 10012 & p.CustomerId != 10013 && p.NextRenewalDate < Convert.ToDateTime("01-01-2015")).ToList();

            ASPxGridView1.DataSource = subscriptions;
            ASPxGridView1.DataBind();

            EconomicInterface ecoInterface = new EconomicInterface();
            //ecoInterface.UpdateSubscriber

            foreach (CustomerSubscription sub in subscriptions)
            {
                //sub.LastRenewalDate = sub.LastRenewalDate.AddYears(-1);
                //sub.NextRenewalDate = sub.NextRenewalDate.AddYears(1);
                
                // TODO: HUSK at undgå PFA
                //ecoInterface.UpdateSubscriber(sub.SubscriptionId, sub, null, db.GetCustomerName(sub.CustomerId));
            }

            //db.SubmitChanges();

        }
    }
}